<template>
  <div class='login-page page-container'>
    <div class="login-box flex">
      <div class="login-left flex flex_ac">
        <div class="left-box">
          <p class="wel">Welcome</p>
          <p>力丸科技后台管理系统</p>
        </div>
      </div>
      <div class="login-right flex_1">
        <el-form ref="form" :model="form" label-width="60px">
          <el-form-item label="用户名">
            <el-input v-model="form.name" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.passd" placeholder="请输入密码" show-password></el-input>
          </el-form-item>
        </el-form>
        <div class="subbox">
          <el-button type="primary" round @click="onSubmit()">立即登录</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  data () {
    return {
      form: {
        name: 'admin',
        passd: 'admin'
      }
    }
  },
  methods: {
    onSubmit() {
      let _this = this
      _this.$api.sumrue.login_api(_this.form).then( async res => {
        console.log(res)
        if(res.code == 1) {
          await window.localStorage.setItem('token', res.data.token)
          _this.$message({
            message: '登录成功',
            type: 'success',
            duration: 2000,
            onClose: function() {
              _this.$router.push('/home')
            }
          })
        } else {
          _this.$message({
            message: '登录失败，请检查账号密码是否正确',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.login-page {
  background: url(../assets/images/login/bg.jpg) no-repeat;
  background-size: 100% 100%;
  padding-top: 1px;
}
.el-form {
  margin-top: 120px;
  padding-right: 20px;
}

.login-box {
  width: 760px;
  height: 420px;
  margin: 100px auto 0;
  background-color: rgb(107, 194, 206, .3);
  border-radius: 3px;
}
.login-left {
  width: 50%;
}
.left-box {
  width: 100%;
  padding-left: 100px;
  color: #ffffff;
  font-weight: 500;
  font-size: 20px;
}
.wel {
  font-size: 24px;
  margin-block: 5px;
}
.login-right {
  height: 100%;
  background-color: #ffffff;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  padding: 1px 10px;
  box-sizing: border-box;
}
.subbox {
  width: 100%;
  margin: 30px 0 0 50px;
}
.el-button {
  width: 80%;
}
</style>
